package UILayer;
import java.util.Scanner;
import CtrLayer.PersonCtr;

/**
 * Write a description of class MainMenu here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class MainMenu
{
    private ProductUI productUi;
    private EmployeeUI employeeUi;
    private OfficeUI officeUi;
    private PersonCtr personCtr;
    
    public MainMenu()
    {
        productUi = new ProductUI();
        employeeUi = new EmployeeUI();
        officeUi = new OfficeUI();
        personCtr = personCtr.getInstance();
    }
    
    public void start()
    { 
        boolean finished = false; 
        while(!finished)
        {
            printMenu();
            switch(reader(4))
            {
                case "0": finished = true; break;
                case "1": productUi.search(); break;
                case "2": employeeUi.start(); break;
                case "3": officeUi.start(); break;
            }
        } 
    }

    private void printMenu()
    {
        System.out.println("\fChoose menu:");
        System.out.println("(0) Exit.");
        System.out.println("(1) Customer.");
        System.out.println("(2) Employee.");
        System.out.println("(3) Office.");
        System.out.println("Make your choice: ");
    }

    private String reader2()
    { 
        Scanner command = new Scanner(System.in); 
        System.out.print(">> "); 
        String c = command.nextLine(); 
        return c;
    }

    private String reader(int limitIndex)
    {
        final String[] validNumbers = {"0","1","2","3","4","5","6","7","8","9"};
        Scanner command = new Scanner(System.in);
        String c = null;
        boolean finished = false;
        while(!finished)
        {
            System.out.print("\n> ");
            c = command.nextLine();
            for(int i=0; i<=limitIndex; i++)
            {
                if(validNumbers[i].equals(c)) 
                    finished = true;
            }
            if(finished == false) 
            {
                System.out.print("\nTry once again");
                c = null;
            }
        }
        return c;
    }
}